package com.heima.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.AdminUserMapper;
import com.heima.admin.service.AdminUserService;
import com.heima.apis.admin.IAdminClient;
import com.heima.apis.user.IUserClient;
import com.heima.model.admin.dtos.AdminUserDto;
import com.heima.model.admin.pojos.AdminUserPojo;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@Transactional
public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUserPojo> implements AdminUserService {

    @Autowired
    private IUserClient iUserClient;

    @Override
    public ResponseResult findList(AdminUserDto dto) {
        ResponseResult list = iUserClient.findList(dto);
        if (list.getCode() != 200) {
            throw new RuntimeException("远程调用服务失败");
        }
        return list;
    }

    @Override
    public ResponseResult success(AdminUserDto dto) {
        ResponseResult success = iUserClient.success(dto);
        if (success.getCode() != 200) {
            throw new RuntimeException("远程调用服务失败");
        }
        return success;
    }

    @Override
    public ResponseResult fail(AdminUserDto dto) {
        ResponseResult fail = iUserClient.fail(dto);
        if (fail.getCode() != 200) {
            throw new RuntimeException("远程调用服务失败");
        }
        return fail;
    }
}
